package likou;

/**
 * @author: Tangxz
 * @email: 1171702529@qq.com
 * @cate: 2020/11/25 07:55
 */
public class _1370 {
    public static void main(String[] args) {

    }

    public String sortString(String s) {
        char[] chars = s.toCharArray();
        int[] num = new int[26];
        for (char c : chars) {
            num[c - 'a']++;
        }
        StringBuilder sb = new StringBuilder();
        while (sb.length() < s.length()) {
            for (int i = 0; i < 26; i++) {
                if (num[i] != 0) {
                    num[i]--;
                    sb.append((char) (i + 'a'));
                }
            }
            for (int i = 25; i >=0; i--) {
                if (num[i] != 0) {
                    num[i]--;
                    sb.append((char) (i + 'a'));
                }
            }
        }
        return sb.toString();
    }
}
